﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Snoop.Web.WebControls
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:LabeledTextBox runat=server></{0}:LabeledTextBox>")]
    public class LabeledTextBox : TextBox
    {
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string Label
        {
            get
            {
                String s = (String)ViewState["Label"];
                return ((s == null) ? string.Empty : s);
            }

            set
            {
                ViewState["Label"] = value;
            }
        }

        protected override void Render(HtmlTextWriter writer)
        {
            writer.WriteBeginTag("label"); //<label>
            writer.WriteAttribute("for", this.ID); // <label for="id">
            writer.WriteAttribute("name", "labelFor" + this.ID); // <label for="id" name="labelForid">
            writer.Write(">");
            writer.Write(Label); // <label for="id" name="labelForid">NombreDelTextbox</label>
            writer.WriteEndTag("label");
            base.Render(writer);
        }
    }
}
